//
//  BaseViewController.m
//  pmmSS
//
//  Created by Mac book on 2017/8/25.
//  Copyright © 2017年 WTFSSD. All rights reserved.
//

#import "BaseViewController.h"

@interface BaseViewController ()

@end

@implementation BaseViewController

-(void)awakeFromNib{
    [super awakeFromNib];

    _titleColor = [UIColor whiteColor];

    //    _titleFont = [Constant navTitleFont];

    [self setUpNavBar];
}

- (void)viewDidLoad {
    [super viewDidLoad];

    // Do any additional setup after loading the view.

 _titleColor = [UIColor whiteColor];

    //    _titleFont = [Constant navTitleFont];

    [self setUpNavBar];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    NSLog(@"内存不足请及时回收");
}


/**
 * 设置导航栏
 */
-(void)setUpNavBar{
    //子类实现

    NSMutableDictionary *titleTextAttributes = [NSMutableDictionary dictionary];

    if(self.navigationController.navigationBar.titleTextAttributes){
        titleTextAttributes = [[NSMutableDictionary alloc] initWithDictionary:self.navigationController.navigationBar.titleTextAttributes];
    }

    if(self.titleColor){
        titleTextAttributes[NSForegroundColorAttributeName] = self.titleColor;
    }

    if(self.titleFont){
        titleTextAttributes[NSFontAttributeName] = self.titleFont;
    }
    self.navigationController.navigationBar.titleTextAttributes = titleTextAttributes;


}



-(void)setTitleFont:(UIFont *)titleFont{
    if (_titleFont == titleFont) {
        return;
    }
    _titleFont = titleFont;
    NSMutableDictionary *titleTextAttributes = [NSMutableDictionary dictionary];

    if(self.navigationController.navigationBar.titleTextAttributes){
        titleTextAttributes = [[NSMutableDictionary alloc] initWithDictionary:self.navigationController.navigationBar.titleTextAttributes];
    }

    if(_titleFont){
        titleTextAttributes[NSFontAttributeName] = _titleFont;
    }

    self.navigationController.navigationBar.titleTextAttributes = titleTextAttributes;}

-(void)setTitleColor:(UIColor *)titleColor{
    if(_titleColor == titleColor){
        return;
    }
    _titleColor = titleColor;
    NSMutableDictionary *titleTextAttributes = [NSMutableDictionary dictionary];

    if(self.navigationController.navigationBar.titleTextAttributes){
        titleTextAttributes = [[NSMutableDictionary alloc] initWithDictionary:self.navigationController.navigationBar.titleTextAttributes];
    }

    if(_titleColor){
        titleTextAttributes[NSForegroundColorAttributeName] = _titleColor;
    }


    self.navigationController.navigationBar.titleTextAttributes = titleTextAttributes;
}


+(instancetype)controller{
    return [[self alloc] init];
}

+(instancetype)controllerWith:(NSDictionary *)config{
    id vc = [self controller];
    [vc setValue:config forKey:@"config"];
    return vc;
}


-(void)setConfig:(NSDictionary *)config{
    _config =config;
    if (_config&&_config[kTitle]) {
        self.title = _config[kTitle];
    }
}



@end

NSString*kTitle = @"title";

